package speed2010.matcher.gui.util;

import javax.swing.JProgressBar;

import speed2010.matcher.gui.FOntologyMatcherGUI;

import speed2010.matcher.gui.util.IProgressable;

public class ProgressBarManager{

	
	public static JProgressBar getCurrentProgressBar()
	{
		JProgressBar progressbar = null;
		
		if(FOntologyMatcherGUI.INSTANCE.getContentPane() instanceof IProgressable)
		{
			IProgressable progressable = (IProgressable) FOntologyMatcherGUI.INSTANCE.getContentPane();
			progressbar = progressable.getCurrentProgressBar();
		}
		
		return progressbar;
	}
	
	public static void setBarProgress(int percentage)
	{
		setBarProgress(percentage, null);
	}
	
	
	public static void setBarProgress(int percentage, String operation)
	{
		JProgressBar progressBar = getCurrentProgressBar();
		if(progressBar != null)
		{
			progressBar.setValue(percentage);
			if(operation != null)
				progressBar.setString(percentage + "% - " + operation);
			else
				progressBar.setString(percentage + "%");
		}
	}
	
	public static boolean isRunningProgress()
	{
		JProgressBar progressBar = getCurrentProgressBar();
		
		return progressBar != null && (progressBar.getValue() != 0 && progressBar.getValue() != 100);
			
	}
	
}
